'''
Descripttion: 
Author: White
Date: 2024-12-30 11:38:12
LastEditTime: 2024-12-30 13:27:39
'''
from flask_login import UserMixin

from db import db


class User(db.Model, UserMixin):
    __tablename__ = 'tb_user'
    id = db.Column(db.String(255), primary_key=True)
    user_name = db.Column(db.String(255))
    password = db.Column(db.String(255))
    role = db.Column(db.String(255))

    def __init__(self, id, user_name, password, role):
        self.id = id
        self.user_name = user_name
        self.password = password
        self.role = role

    def get(self):
        return {
            "id": self.id,
            "user_name": self.user_name,
            "password": self.password,
            "role": self.role
        }

    def has_permission(self, permission):
        return permission in self.role

    def __repr__(self):
        return f'<User {self.user_name}>'
